<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('医院列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>医院名称：</label>
                            <input type="text" name="hospitalName"/>
                        </li>
                        <li>
                            <label>医院等级：</label>
                            <select name="hospitalLevel" th:with="type=${@dict.getType('hospitel_level')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>医院类型：</label>
                            <select name="hospitalType" th:with="type=${@dict.getType('hospitel_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>排序：</label>
                            <input type="text" name="sort"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status" th:with="type=${@dict.getType('user_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>地址：</label>
                            <input type="text" name="address"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="peizhen:hospital:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="peizhen:hospital:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="peizhen:hospital:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="peizhen:hospital:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-page-size="10"
                   data-show-custom-view="true" data-custom-view="customViewFormatter"
                   data-show-custom-view-button="true">
            </table>
        </div>

    </div>
</div>

<template id="profileTemplate">
    <div class="col-sm-4" style="height: 200px">
        <div class="contact-box">
            <a href="profile.html">
                <div class="col-sm-4">
                    <div class="text-center">
                        <img alt="image" class="img-circle m-t-xs img-responsive" src="%IMAGE%">
                        <div class="m-t-xs font-bold">%id%</div>
                    </div>
                </div>
                <div class="col-sm-8">
                    <h3><strong style="overflow: hidden;text-overflow-ellipsis: ellipsis;white-space: nowrap">%hospitalName%</strong></h3>
                    <p> %hospitalLevel% %hospitalType%</p>
                    <address>
                        <strong style="overflow: hidden;text-overflow-ellipsis: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;">地址:
                            %address%</strong>
                    </address>
                </div>
                <div class="clearfix"></div>
            </a>
        </div>
    </div>
</template>

<div th:include="include :: footer"></div>
<th:block th:include="include :: bootstrap-table-custom-view-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('peizhen:hospital:edit')}]];
    var removeFlag = [[${@permission.hasPermi('peizhen:hospital:remove')}]];
    var hospitalLevelDatas = [[${@dict.getType('hospitel_level')}]];
    var hospitalTypeDatas = [[${@dict.getType('hospitel_type')}]];
    var statusDatas = [[${@dict.getType('user_status')}]];
    var prefix = ctx + "peizhen/hospital";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "医院",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'hospitalName',
                    title: '医院名称'
                },
                {
                    field: 'hospitalLevel',
                    title: '医院等级',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(hospitalLevelDatas, value);
                    }
                },
                {
                    field: 'hospitalType',
                    title: '医院类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(hospitalTypeDatas, value);
                    }
                },
                {
                    field: 'hotelImage',
                    title: '医院图片'
                },
                {
                    field: 'sort',
                    title: '排序'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'address',
                    title: '地址'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function customViewFormatter(data) {
        var template = $('#profileTemplate').html()
        var view = ''
        $.each(data, function (i, row) {
            view += template.replace('%hospitalName%', row.hospitalName)
                .replace('%IMAGE%', row.hotelImage)
                .replace('%id%', row.id)
                .replace('%hospitalLevel%', row.hospitalLevel)
                .replace('%hospitalType%', row.hospitalType)
                .replace('%address%', row.address);
        })

        return `<div class="row mx-0">${view}</div>`
    }
</script>
</body>
</html>